
<section class="create-class class-top classes-set">
    <div class="container">
        <div class="row">   
            <div class="col-lg-12 column12">         
                <div id="Bread">
                    <ol class="breadcrumb">
                        <li><a href="<?php echo SITE_URL; ?>">Home</a></li>
                        <li><a href="<?php echo $this->createUrl('/myskillhippo'); ?>">My Skillhippo</a></li>
                        <li class="active">Create a Class</li>
                    </ol>
                </div><!--bread-->
            </div> <!--basket col--> 
        </div>
        <div class="tab-pane fade in active photouploding" id="teach">
            <h3>Step 3: <span>Add a class photo</span></h3>
            <hr class="photohr">
            <div class="row">                          
                <div class="picture-select">
                    <p><?php echo Message::CLASS_PHOTO ?></p>
                    <?php
                    $form = $this->beginWidget('GxActiveForm', array(
                        'id' => 'classes-form',
                        'htmlOptions' => array('enctype' => 'multipart/form-data'),
                    ));

                    $this->widget('xupload.XUpload', array(
                        'url' => Yii::app()->createUrl("classImage/upload"),
                        'model' => $photos,
                        'htmlOptions' => array('id' => 'classes-form'),
                        'attribute' => 'file',
                        'multiple' => true,
                        'showForm' => false,
                        'options' => array(
                            'maxNumberOfFiles' => SkillConfig::MAX_FILE_UPLOAD_LIMIT,
                            'maxFileSize' => SkillConfig::MAX_IMAGE_SIZE_UPLOAD,
                        ),
                            )
                    );
                    ?> <!--picture box-->
                    <div id="errortext"class="errorMessage"></div>
                    <div class="row pic-btn picture-btn ">
                        <div class="col-lg-12 column12 mopo">
                            <input type="button" class="btn twoBtn" value="Back" id="<?php echo $authKey; ?>" onclick="setAuthKey(this.id, 'ClassVenue/Classvenue')">
                            <?php echo GxHtml::submitButton(Yii::t('app', 'Save & Continue'), array('class' => 'btn', 'id' => 'saveClassImage')); ?>
                        </div>
                    </div>   
                    <?php $this->endWidget(); ?>
                    <div class="gap2"></div>
                    <div class="gap"></div>            
                </div>
                <?php
                if (isset($authKey)) {
                    $classes = Classes::model()->findByAttributes(array('auth_key' => $authKey));
                    $classWithImage = Classes::getclassWithImage($classes->id);
                    $dataProvider = new CArrayDataProvider($classWithImage, array(
                        'id' => 'classimage',
                        'sort' => array(
                            'attributes' => array(
                                'id', 'photo', 'class_id',),
                        ),
                        'pagination' => array(
                            'pageSize' => 10,),));


                    $this->widget('zii.widgets.grid.CGridView', array(
                        'id' => 'classimage-grid',
                        'dataProvider' => $dataProvider,
                        'columns' => array(
                            array(
                                'name' => 'Image',
                                'type' => 'image',
                                'value' => 'Classes::classImageingridView($data)',
                                'htmlOptions' => array('style' => 'text-align: center'),
                            ),
                            array(
                                'name' => 'Primary image',
                                'value' => 'ClassImage::isPrimaryImage($data)',
                                'htmlOptions' => array('style' => 'text-align: center;padding:5px;'),
                            ),
                            array(
                                'id' => 'autoId',
                                'header' => 'Delete Image',
                                'class' => 'CCheckBoxColumn',
                                'selectableRows' => '50',
                                'checkBoxHtmlOptions' => array('name' => 'idList[]', 'onclick' => 'deleteAllRecord()', 'class' => 'deleteAllRecord'),
                            ),
                        ),
                    ));
                    $count = count($classWithImage) == '0' ? '' : count($classWithImage);
                }
                echo '<input type="hidden" name="imagevalidation" id="imagevalidation" value=>';
                echo '<input type="hidden" name="addimagevalidation" id="addimagevalidation" value=>';
                ?>

            </div>
        </div>
     

        <script type="text/javascript">
            function ChangeStatus(id, classid) {
                bootbox.confirm("Are you sure want to use this as the workshop's primary image?", function(result) {
                    if (result != false) {
                       var ajaxloader = "<?php echo baseUrl() . "images/" . '/ajax-loader.gif'; ?>"
                        $("#imgadmin_" + id).attr("src", ajaxloader)
                        $("#imgadmin_" + id).attr("onclick", "")
                        jQuery.ajax({
                            'type': 'POST',
                            'url': "<?php echo Yii::app()->createUrl("classImage/primaryImage"); ?>",
                            'data': 'YII_CSRF_TOKEN=' + $('input[name="YII_CSRF_TOKEN"]').val() + '&id=' + id + '&classid=' + classid,
                            'beforeSend': function(jqXHR, settings) {
                                $("#imgadmin_" + id).attr("src", ajaxloader)
                                $("#imgadmin_" + id).attr("onclick", "")
                            },
                            'success': function(json) {
                                var data = jQuery.parseJSON(json);
                                if (data.primary_image == '1') {
                                    $("img[src$='active.png'][name='primary']").attr("src", "<?php echo baseUrl() . "images/" . 'deactive.png' ?>");
                                    var enableImg = "<?php echo baseUrl() . "images/" . 'active.png' ?>";
                                    $("#imgadmin_" + id).attr("src", enableImg);
                                    $("#imgadmin_" + id).attr("onclick", "ChangeStatus(" + id + "," + data.classes_id + ")");
                                }
                            },
                            'cache': false
                        })
                    }
                });

            }




            function getPrimaryImage(id) {
                bootbox.confirm("Are you sure want to use this as the workshop's primary image?", function(result) {
                    if (result != false) {
                        var imagename = id;
                        $.post("<?php echo Yii::app()->createUrl("classImage/makePrimaryImage"); ?>", {'YII_CSRF_TOKEN': $('input[name="YII_CSRF_TOKEN"]').val(), imagename: imagename}, function(result) {
                        });
                    }
                });
            }


            function deleteAllRecord() {
                var idList = $(".deleteAllRecord:checked").serialize();
                if (idList) {
                    bootbox.confirm("Are you sure want to delete image ?", function(result) {
                        if (result != false) {
                            $.post("<?php echo Yii::app()->createUrl("classImage/deleteClassImage"); ?>", idList, function(response) {
                                location.reload('#classImage-id');
                            });
                        }
                    });
                }
            }
            $("#autoId_all").change(function() {
                $('.deleteAllRecord').attr('checked', 'checked');
                var idList = $(".deleteAllRecord:checked").serialize();
                if (idList) {
                    bootbox.confirm("Are you sure want to delete image ?", function(result) {
                        if (result != false) {
                            $.post("<?php echo Yii::app()->createUrl("classImage/deleteClassImage"); ?>", idList, function(response) {
                                location.reload('#classImage-id');
                            });
                        }
                    });
                }
                $('.deleteAllRecord').removeAttr('checked');
            })
            $('.multipleImage').click(function() {
                var k = $('#addimagevalidation').val();
                if (k == 1) {
                    $('#imagevalidation').val('1')
                }
            })
            $('#XUploadForm_file').click(function() {
                $('#addimagevalidation').val('1')
            })
            $('.cancelImage').click(function() {
                $('#addimagevalidation').val('')
                $('#imagevalidation').val('')
            })
            $("#saveClassImage").click(function() {
                var image1 = $('#addimagevalidation').val();
                var image2 = $('#imagevalidation').val();
                if (image2 == '' || image1 == '')
                {
                    $("#errortext").text('Please Upload image');
                    return false;
                }

            });

        </script><!--picture select div end here-->  
    </div><!--venue tab row end here-->
</section>